﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using ZhengMeiJiSettingUI.ModelEntity;
namespace ZhengMeiJiSettingUI.Data
{
    public class FinshGetServer
    {
        public async Task<IEnumerable<FinishedGet_Entity>> Getlist()
        {
            using (HttpClientHandler clientHandler = new HttpClientHandler())
            {
                clientHandler.ServerCertificateCustomValidationCallback = (message, cert, chain, error) => true;
                using (HttpClient client = new HttpClient(clientHandler))
                {
                    var request = new HttpRequestMessage(HttpMethod.Get, $"{AppSettingsJson.GetAppSettings().GetSection("ConnectionUrl")["DefaultConnection"]}/api/FinshGet");
                    request.Headers.Add("Accept", "text / plain");
                    try
                    {
                        var response = await client.SendAsync(request);
                        if (response.IsSuccessStatusCode)
                        {
                            var wwwwww = await response.Content.ReadAsStringAsync();
                            using var responseStream = await response.Content.ReadAsStreamAsync();
                            var result = await JsonSerializer.DeserializeAsync
                                <IEnumerable<FinishedGet_Entity>>(responseStream);
                            return result;
                        }
                        else
                        {
                            return null;
                            //  getBranchesError = true;
                        }
                    }
                    catch (Exception e)
                    {

                        return null;
                    }
                }
            }
        }



        public async Task<string> TaskCreat(int ID)
        {
            using (HttpClientHandler clientHandler = new HttpClientHandler())
            {
                clientHandler.ServerCertificateCustomValidationCallback = (message, cert, chain, error) => true;
                using (HttpClient client = new HttpClient(clientHandler))
                {
                    var request = new HttpRequestMessage(HttpMethod.Get, $"{AppSettingsJson.GetAppSettings().GetSection("ConnectionUrl")["DefaultConnection"]}/api/TaskCreat/FinishedGet?Devid={ID}");
                    request.Headers.Add("Accept", "text / plain");
                    try
                    {
                        var response = await client.SendAsync(request);
                        if (response.IsSuccessStatusCode)
                        {

                            var result = await response.Content.ReadAsStringAsync();
                            return result;
                        }
                        else
                        {
                            return null;
                            //  getBranchesError = true;
                        }
                    }
                    catch (Exception e)
                    {

                        return null;
                    }
                }
            }
        }
    }
}
